package com.mallcloud.mall.mall.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.common.excel.annotation.ResponseExcel;
import com.mallcloud.mall.mall.api.entity.MallAppSettingModel;
import com.mallcloud.mall.mall.service.MallAppSettingService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "商城app界面设置管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/mall/appSetting")
public class MallAppSettingController {
    private final MallAppSettingService appSettingService;

    @ApiOperation("分页查询")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('mall_appsetting_view')")
    public R<IPage<MallAppSettingModel>> page(Page page, MallAppSettingModel dto) {
        return R.ok(appSettingService.pageAppSetting(page, dto));
    }

    @ApiOperation("通过id查询")
    @GetMapping("/getInfo")
    @PreAuthorize("@pms.hasPermission('mall_appsetting_view')")
    public R<MallAppSettingModel> getInfo(MallAppSettingModel appSetting) {
        return R.ok(appSettingService.getAppSettingById(appSetting.getId()));
    }

    @ApiOperation("新增")
    @PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('mall_appsetting_add')")
    public R<Boolean> save(@RequestBody MallAppSettingModel appSetting) {
        return R.ok(appSettingService.saveAppSetting(appSetting));
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    @PreAuthorize("@pms.hasPermission('mall_appsetting_edit')")
    public R<Boolean> updateById(@RequestBody MallAppSettingModel appSetting) {
        return R.ok(appSettingService.updateAppSetting(appSetting));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('mall_appsetting_del')")
    public R<Boolean> removeById(@PathVariable Long id) {
        return R.ok(appSettingService.removeAppSettingById(id));
    }

    @ApiOperation("批量删除商城app界面设置")
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('mall_appsetting_del')")
    public R<Boolean> removeByIds(@RequestBody List<Long> ids) {
        return R.ok(appSettingService.removeAppSettingByIds(ids));
    }

}
